#include "../inc/swilib.h"

extern const char IDX_PATH[64];

const char recent_file[]="%srecent";
char recent[256];

char * RecentFilename()
{
  unsigned int err;
  char str[256];
  sprintf(str,recent_file,IDX_PATH);
  int f;
  if ((f=fopen(str,A_ReadOnly+A_BIN,P_READ,&err))!=-1)
  {
    recent[fread(f,recent,256,&err)]=0;
    fclose(f,&err);    
    return recent;
  }
  else 
    return 0;  
};

void SetRecentFilename(char * fn)
{ 
  unsigned int err;
  char str[256];
  int f;
  sprintf(str,recent_file,IDX_PATH);
  if ((f=fopen(str,A_ReadWrite+A_BIN+A_Create+A_Truncate,P_READ+P_WRITE,&err))!=-1)
  {
//    fread(f,&def_set,sizeof(IDX_DATA),&err);
    strcpy(recent,fn);
    fwrite(f,recent,strlen(fn),&err);
    fclose(f,&err);    
  }
  else
    ShowMSG(2,(int)"Failed to write RECENT");
};
